package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 风险偏离表(risk_deviation)迁移脚本
 */
public class A004_RiskDeviationMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A004_RiskDeviationMigrationScript() {
        super(
            "risk_deviation",
            "风险偏离数据迁移",
            "ra_deviate",
            "risk_deviation",
            4
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_deviation (\n" +
               "    id,\n" +
               "    tenant_id,\n" +
               "    deviation_name,\n" +
               "    is_default,\n" +
               "    guide_word,\n" +
               "    parameter,\n" +
               "    operating_range,\n" +
               "    working_limit,\n" +
               "    design_limit,\n" +
               "    unit,\n" +
               "    measurement_location,\n" +
               "    sort_num,\n" +
               "    create_time,\n" +
               "    update_time,\n" +
               "    create_by,\n" +
               "    update_by,\n" +
               "    is_del\n" +
               ")\n" +
               "SELECT\n" +
               "    id,\n" +
               "    1 as tenant_id,\n" +
               "    LEFT(drift_name, 10) as deviation_name,\n" +
               "    is_default,\n" +
               "    particle_word,\n" +
               "    arguments,\n" +
               "    operating_limits,\n" +
               "    working_limit,\n" +
               "    design_limit,\n" +
               "    units,\n" +
               "    measure_site,\n" +
               "    sort_no,\n" +
               "    DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s'),\n" +
               "    DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%s'),\n" +
               "    1,\n" +
               "    1, \n" +
               "    is_del\n" +
               "FROM risk_lunnan_test.ra_deviate;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "    id,\n" +
               "    tenant_id,\n" +
               "    drift_name,\n" +
               "    is_default,\n" +
               "    particle_word,\n" +
               "    arguments,\n" +
               "    operating_limits,\n" +
               "    working_limit,\n" +
               "    design_limit,\n" +
               "    units,\n" +
               "    measure_site,\n" +
               "    sort_no,\n" +
               "    create_time,\n" +
               "    update_time,\n" +
               "    is_del\n" +
               "FROM risk_lunnan_test.ra_deviate;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_deviation (\n" +
               "    id,\n" +
               "    tenant_id,\n" +
               "    deviation_name,\n" +
               "    is_default,\n" +
               "    guide_word,\n" +
               "    parameter,\n" +
               "    operating_range,\n" +
               "    working_limit,\n" +
               "    design_limit,\n" +
               "    unit,\n" +
               "    measurement_location,\n" +
               "    sort_num,\n" +
               "    create_time,\n" +
               "    update_time,\n" +
               "    create_by,\n" +
               "    update_by,\n" +
               "    is_del\n" +
               ")";
    }
}
